<?php
namespace backend\controllers;


use Yii;
use backend\models\LoginForm;
use yii\filters\VerbFilter;

/**
 * Site controller
 */
class SiteController extends MyController
{
    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                   // 'delete' => ['post'],
                ],
            ],
        ];
    }

    /**
     * @inheritdoc
     */
    public function actions()
    {
        return [
            'error' => [
                'class' => 'yii\web\ErrorAction',
            ],
            'captcha' => [
                'class' => 'yii\captcha\CaptchaAction',
                'fixedVerifyCode' => YII_ENV == 'dev' ||YII_ENV_TEST ? 'test' : null,
                'minLength'=>4,
                'maxLength'=>4
                //'backColor'=>''
            ],

        ];
    }
    
    /**
     * 首页
     * @return Ambigous <string, string>
     */
    public function actionIndex()
    {   
       return $this->render('index');
        
    }
   
    /**
     * 登陆
     */
    public function actionLogin()
    {   
        
        $this->layout = 'main-login';
        
        if (!\Yii::$app->user->isGuest) {
            return $this->goHome();
        }
        
        $model = new LoginForm();
        
        
        if ($model->load(Yii::$app->request->post()) && $model->login()) {
            //验证成功
            Yii::$app->session['admin_idtoken'] = md5($model->getUser()->no.Yii::$app->request->hostInfo);
            Yii::$app->session['admin_name'] = $model->getUser()->name;
            Yii::$app->session['admin_id'] = $model->getUser()->no;
            // return $this->redirect(['site/index']);
            return $this->goBack();
        } else {
            return $this->render('login', [
                'model' => $model
            ]);
        }
    }
    
    /**
     * 退出
     */
    public function actionLogout()
    {
        Yii::$app->user->logout();

        return $this->goHome();
    }
    
    public function actionResetPassword(){
        return $this->render('reset_password');
    }
    
}
